package com.dq.utils;

import com.dq.vo.ResultMessage;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.util.StringUtils;

/**
 * @description: 消息工具类
 * @author: webSocket-chat_小强 (QQ:2680825683)
 * @className: MessageUtil
 * @since: 2023/2/8 15:24
 */
public class MessageUtil {

    public static String getMessage(boolean isSystemMessage,String fromName,Object message){
        try {
            ResultMessage result = new ResultMessage();
            result.setSystem(isSystemMessage);
            result.setMessage(message);
            if (!StringUtils.isEmpty(fromName)){
                result.setFromName(fromName);
            }
            ObjectMapper mapper = new ObjectMapper();
            return mapper.writeValueAsString(result);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
